package com.ioday01demo;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("pw.txt");
        //转换流连接字节流和字符流
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //字符缓冲流底层是8kb的字符数组 没存满需要flush
        BufferedWriter bw = new BufferedWriter(osw);
        //PrintWriter底层是多个流连接  有每次回车都会 自动flush的参数
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("请输入");
            String line = sc.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);

        }
        pw.close();

    }
}
